﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace FGrubert.VpcManager
{
    /// <summary>
    /// Represents a single network interface of a machine
    /// </summary>
    public class Nic
    {
        private string name;
        /// <summary>
        /// Gets or sets the name of the interface
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private int id;
        /// <summary>
        /// Gets or sets the ID of the nic
        /// </summary>
        public int Id
        {
            get { return id; }
        }

        private string mac;
        /// <summary>
        /// Gets or sets the mac address
        /// </summary>
        public string Mac
        {
            get { return mac; }
            set { mac = value; }
        }

        private Machine machine;
        /// <summary>
        /// Gets the machine that this NIC is associated to
        /// </summary>
        public Machine Machine
        {
            get { return machine; }
        }

        /// <summary>
        /// Creates a new nic object
        /// </summary>
        /// <param name="machine">The machine this NIC is associated to</param>
        /// <param name="node">The node containing the information about the nic</param>
        public Nic(Machine machine, XmlNode node)
        {
            this.machine = machine;
            this.name = node.SelectSingleNode("virtual_network/name").InnerText;            
            this.id = Convert.ToInt32(node.Attributes["id"].Value);
            if (node.SelectSingleNode("ethernet_card_address") != null)
                this.mac = node.SelectSingleNode("ethernet_card_address").InnerText;
            else
                this.mac = "";
            
        }

        /// <summary>
        /// Resets the MAC of this NIC
        /// </summary>
        public void ResetMac()
        {
            this.machine.ResetNicMac(this.id);
        }
    }
}
